package li.nibble.twittertido;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;

//public class Main extends ListActivity {
public class Main extends TabActivity {
	/** Called when the activity is first created. */

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		

		// DataBase.printTweet(this, DataBase.TABLE_QUEUE);
		// DataBase.printPrefences(this);

		initAds();

		TabHost tabs = (TabHost) findViewById(android.R.id.tabhost);

		TabSpec homeTab = tabs
				.newTabSpec("home")
				.setIndicator(getText(R.string.home),
						getResources().getDrawable(R.drawable.ic_tab_home))
				.setContent(new Intent(this, HomeTab.class));

		TabSpec topTab = tabs
				.newTabSpec("top")
				.setIndicator(getText(R.string.top),
						getResources().getDrawable(R.drawable.ic_tab_top))
				.setContent(new Intent(this, TopTweetsTab.class));

		TabSpec randomTab = tabs
				.newTabSpec("random")
				.setIndicator(getText(R.string.random),
						getResources().getDrawable(R.drawable.ic_tab_random))
				.setContent(new Intent(this, RandomTab.class));

		TabSpec topUsersTab = tabs
				.newTabSpec("topUsers")
				.setIndicator(getText(R.string.top_users),
						getResources().getDrawable(R.drawable.ic_tab_top_users))
				.setContent(new Intent(this, TopUsersTab.class));

		TabSpec queueTab = tabs
				.newTabSpec("queue")
				.setIndicator(getText(R.string.queue),
						getResources().getDrawable(R.drawable.ic_tab_queue))
				.setContent(new Intent(this, QueueTab.class));

		tabs.addTab(homeTab);
		tabs.addTab(topTab);
		tabs.addTab(randomTab);
		tabs.addTab(topUsersTab);
		tabs.addTab(queueTab);

		findViewById(R.id.share_aplication).setOnClickListener(
				new OnClickListener() {
					@Override
					public void onClick(View arg0) {
						Intent intent = new Intent(Intent.ACTION_SEND);
						intent.setType("text/plain");
						intent.putExtra(Intent.EXTRA_TEXT,
								getText(R.string.share_application_text));
						intent.putExtra(Intent.EXTRA_SUBJECT,
								getText(R.string.share_application_subject));
						startActivity(Intent.createChooser(intent,
								getText(R.string.share_application)));
					}
				});

	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.main_menu, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.help:
			startActivity(new Intent(this, Tutorial_0.class));
			return true;
		case R.id.about:
			return true;
		case R.id.feedback:
			startActivity(new Intent(this, FeedBack.class));
			return true;
		case R.id.settings:
			startActivity(new Intent(this, MainPreferences.class));
			return true;
		default:
			return super.onOptionsItemSelected(item);
		}
	}

	private void initAds() {
		AdView adView = new AdView(this, AdSize.BANNER, Constants.ADMOB);
		LinearLayout layout = (LinearLayout) findViewById(R.id.ads);
		layout.addView(adView);
		adView.loadAd(new AdRequest());
	}
}